package com.qgs.waf.gen;

import java.util.List;
import java.util.Random;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisConnectionUtils;
import org.springframework.data.redis.core.RedisTemplate;

import com.qgs.waf.jedis.RedisKeys;
import com.qgs.waf.util.RandomUtil;
import com.qgs.waf.util.StringUtil;

public class GenCustomerDate {
	@Autowired
	private static RedisTemplate rt;

	public static void test() {
		ApplicationContext ac = new ClassPathXmlApplicationContext("classpath*:applicationContext*.xml", "classpath*:mybatis-*.xml");
		rt = (RedisTemplate) ac.getBean("jedisTemplate");
		RedisConnectionFactory factory = rt.getConnectionFactory();
		RedisConnection redisConnection = RedisConnectionUtils.getConnection(factory);
		redisConnection.openPipeline();
		// 生成随机数
		genRandomHashDate(redisConnection);
		List results = redisConnection.closePipeline();
		System.out.println(results);
		redisConnection.close();
		System.out.println("end ......");
	}

	public static void genRandomHashDate(RedisConnection redisConnection) {
		List<String> customers = StringUtil.getFixedLengthStr("C0000", 15);
		int ran;
		for (int i = 1; i < 10000; i++) {
			ran = new Random().nextInt(customers.size());
			redisConnection.hSet(RedisKeys.getAttackSummaryByCustomerKey(customers.get(ran)).getBytes(), RedisKeys.getDataOrdinary(RandomUtil.randomDate("2000-01-01", null)).getBytes(), String.valueOf(new Random().nextInt(500)).getBytes());
		}
	}

	public static void main(String[] args) {
		test();
	}
}
